#!/bin/bash

srpmfile="openvswitch-2.8.1-2.1fc28.el7.src.rpm"
specfile="openvswitch.spec"

if [ $# -eq 0 ];then
  echo "Usage: $0 -ba|-bp"
  exit
fi
HOME=/tmp/`whoami`
builddir=${HOME}/rpmbuild
mkdir -p  $builddir/SOURCES $builddir/SPECS

if [ ! -f $srpmfile ]; then
    wget http://cbs.centos.org/kojifiles/packages/openvswitch/2.8.1/2.1fc28.el7/src/${srpmfile}
fi

rpm -ivh $srpmfile
cp *.patch ${builddir}/SOURCES/

if [ ! -f $specfile ]; then
  cp ${builddir}/SPECS/$specfile ./
fi

cp ${specfile} ${builddir}/SPECS/
cd ${builddir}/SPECS && rpmbuild ${1} ${specfile}
